from fastapi import APIRouter, Depends, Request

from forward.common.enums import LoginTypeEnum
from forward.api.h5.schemas.login import (
    FrontLoginCheckInSchema,
    FrontRegisterInSchema,
)
from forward.api.h5.service.login import LoginService, LoginService
from forward.http_base import unified_resp

router = APIRouter(prefix="/login")


@router.get("/code_url")
@unified_resp
async def get_code_url(
    url: str, login_service: LoginService = Depends(LoginService.instance)
):
    return await login_service.get_code_url(redirect_uri=url)


# @router.get("/account_login")
# async def account(
#     login_in: AccountLoginInSchema,
#     login_service: LoginService = Depends(LoginService.instance),
# ):
#     return await login_service.account_login(login_in)


# @router.get("/wx_oa_login")
# async def wx_oa_login(request: Request):
#     return ""


# @router.get("/wx_nmp_login")
# async def wx_nmp_login(request: Request):
#     print("get_code_url", request.url)
#     return ""


# @router.get("/mobile_login")
# async def mobile_login(request: Request):
#     print("get_code_url", request.url)
#     return ""


@router.post("/check")
@unified_resp
async def login_check(
    params: FrontLoginCheckInSchema,
    login_service: LoginService = Depends(LoginService.instance),
):
    """
    登录管理
    :return:
    """
    scene = params.scene
    if scene == LoginTypeEnum.account:
        return await login_service.account_login(params.username, params.password)
    elif scene == LoginTypeEnum.sms:
        return await login_service.sms_login(params.mobile, params.code)
    elif scene == LoginTypeEnum.wechat_mnp:
        return await login_service.mnp_login(params.code, params.client)
    elif scene == LoginTypeEnum.wechat_office:
        return await login_service.wechat_office(params.code, params.client)


@router.post("/register")
@unified_resp
async def register(
    params: FrontRegisterInSchema,
    login_service: LoginService = Depends(LoginService.instance),
):
    """
    注册
    :return:
    """
    return await login_service.register(params)
